<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!--edge浏览器H5兼容设置-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--360浏览器H5兼容设置-->
    <meta name="renderer" content="webkit"/>
    <title>学子商城</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--导入核心文件-->
    <script src="../bootstrap3/js/holder.js"></script>
    <script src="../bootstrap3/jquery-1.9.1.min.js"></script>
    <script src="../bootstrap3/js/bootstrap.js"></script>
    <link rel="stylesheet" href="../css/element-plus@2.3.9_dist_index.css" />
    <script src="../js/vue@3.3.4.global.js"></script>
    <script src="../js/element-plus@2.3.9_dist_index.full.js"></script>
    <script src="../js/axios.js"></script>
    <script src="../js/request.js"></script>
    <!-- 字体图标 -->
    <link rel="stylesheet" type="text/css" href="../bootstrap3/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css"/>
    <link rel="stylesheet" type="text/css" href="../css/layout.css"/>
    <link rel="stylesheet" type="text/css" href="../css/top.css"/>
    <link rel="stylesheet" type="text/css" href="../css/footer.css"/>
    <link rel="stylesheet" type="text/css" href="../css/product.css"/>
    <link rel="stylesheet" type="text/css" href="../css/imgmove.css"/>
</head>

<body id="app">
<!--头部-->
<header class="header">
    <!--学子商城logo-->
    <div class="row">
        <div class="col-md-3">
            <a href="index.html">
                <img src="../images/index/stumalllogo.png"/>
            </a>
        </div>
        <!--快捷选项-->
        <div class="col-md-9 top-item">
            <ul class="list-inline pull-right">
                <li><a href="favorites.html"><span class="fa fa-heart"></span>&nbsp;收藏</a></li>
                <li class="li-split">|</li>
                <li><a href="orders.html"><span class="fa fa-file-text"></span>&nbsp;订单</a></li>
                <li class="li-split">|</li>
                <li><a href="cart.html"><span class="fa fa-cart-plus"></span>&nbsp;购物车</a></li>
                <li class="li-split">|</li>
                <li>
                    <!--下列列表按钮 ：管理-->
                    <div class="btn-group">
                        <button type="button" class="btn btn-link dropdown-toggle" data-toggle="dropdown">
                            <span id="top-dropdown-btn"><span class="fa fa-gears"></span>&nbsp;管理 <span
                                    class="caret"></span></span>
                        </button>
                        <ul class="dropdown-menu top-dropdown-ul" role="menu">
                            <li><a href="password.html">修改密码</a></li>
                            <li><a href="userdata.html">个人资料</a></li>
                            <li><a href="upload.html">上传头像</a></li>
                            <li><a href="address.html">收货管理 </a></li>
                        </ul>
                    </div>
                </li>
                <li class="li-split">|</li>
                <li v-if="isLogin"><span class="fa fa-user"></span>&nbsp;{{username}}</li>
                <li v-if="!isLogin"><a href="login.html"><span class="fa fa-user"></span>&nbsp;去登录</a></li>
            </ul>
        </div>
    </div>
</header>
<!--导航 -->
<!--分割导航和顶部-->
<div class="row top-nav">
    <div class="col-md-6">
        <ul class="nav nav-pills">
            <li>
                <a href="#"></a>
            </li>
            <li class="active"><a href="index.html"><span class="fa fa-home"></span></a></li>
            <li><a href="#">秒杀</a></li>
            <li><a href="#">优惠券</a></li>
            <li><a href="#">学子VIP</a></li>
            <li><a href="#">外卖</a></li>
            <li><a href="#">超市</a></li>
        </ul>
    </div>
    <div class="col-md-6">
        <form action="search.html" class="form-inline pull-right" role="form">
            <div class="form-group">
                <input type="text" class="form-control" id="search" name="search" placeholder="请输入商品名称进行搜索">
            </div>
            <button type="submit" class="btn btn-default btn-sm"><span class="fa fa-search"></span></button>
        </form>
    </div>
</div>
<!--头部结束-->
<!--导航结束-->
<!--商品信息展示开始-->
<div class="container">
    <div class="col-md-offset-1 col-md-10">
        <div class="col-md-6">
            <div v-for="img in product.imgs" :data="img.big" class="img-big move-img col-md-12" style="display: block">
                <img :src="img.big" class="img-responsive"/>
            </div>
<!--            <div data="2" class="img-big move-img col-md-12">-->
<!--                <img src="../images/portal/11DELLran7000R1605Ssilvery/2_big.png" class="img-responsive"/>-->
<!--            </div>-->
            <div v-for="img in product.imgs" :data="img.small" class="col-md-2 img-small">
                <img :src="img.small" class="img-responsive"/>
            </div>
<!--            <div data="2" class="col-md-2 img-small">-->
<!--                <img src="../images/portal/11DELLran7000R1605Ssilvery/2.jpg" class="img-responsive"/>-->
<!--            </div>-->
        </div>
        <div class="col-md-6">
            <h3 class="col-md-12" :title="product.title">{{product.title}}</h3>
            <p class="col-md-12 text-row-1"><small>{{product.sellPoint}}</small></p>
            <div class="col-md-12 price-bar">
                <small>学员售价：</small> ¥<span>{{product.price}}</span>
                <div><small>*退货补运费 *7天无理由退货 *24小时快速退款 </small></div>
            </div>
            <form class="form-inline product-form col-md-12" role="form">
                <div class="col-md-12 form-space">
                    <label for="num">数量：</label>
                    <input type="number" class="form-control" id="num" value="1" min="1" max="100">
                </div>
                <div class="col-md-12 form-space">
                    <p><small><b>学子商城</b>发货并提供售后服务,今日下单,明日送达</small></p>
                </div>
                <div class="col-md-12 form-space">
                    <input class="btn btn-primary btn-lg btn-block" type="button" value="立即购买">
                </div>
                <div class="col-md-12 form-space">
                    <button type="button" class="btn btn-default go-cart" @click="addToCart">
                        <span class="fa fa-cart-plus"></span> 加入购物车
                    </button>
                    <button type="button" v-if="!product.isFavorite" class="btn btn-default" @click="addToFavorites">
                        <span class="fa fa-heart-o"></span> 加入收藏
                    </button>
                    <button type="button" v-else class="btn btn-default" @click="removeFromFavorites">
                        <span class="fa fa-heart"></span> 取消收藏
                    </button>
                </div>
            </form>
        </div>
    </div>
    <!--商品信息展示结束-->
    <!--售后信息开始-->
    <div class="col-md-offset-1 col-md-10">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h2 class="panel-title">售后保障</h2>
            </div>
            <div class="panel-body ">
                <div class="row">
                    <div class="col-md-1 saled-icon"><span class="fa fa-shield"></span></div>
                    <div class="col-md-11 saled-title">正品保障</div>
                </div>
                <div class="row">
                    <p class="col-md-offset-1 col-md-11 saled-content">
                        学子商城向您保证所售商品均为正品行货，学子商城自营商品开具机打发票或电子发票。</p>
                </div>

                <div class="row">
                    <div class="col-md-1 saled-icon"><span class="fa fa-wrench"></span></div>
                    <div class="col-md-11 saled-title">厂家服务</div>
                </div>
                <div class="row">
                    <p class="col-md-offset-1 col-md-11 saled-content">本产品全国联保，享受三包服务，质保期为：二年质保</p>
                </div>
                <div class="row">
                    <div class="col-md-1 saled-icon"><span class="fa fa-heartbeat"></span></div>
                    <div class="col-md-11 saled-title">郑重承诺</div>
                </div>
                <div class="row">
                    <p class="col-md-offset-1 col-md-11 saled-content">学子商城销售并发货的商品，由学子商城提供发票和相应的售后服务。请您放心购买！
                        <br/>
                        注：因厂家会在没有任何提前通知的情况下更改产品包装、产地或者一些附件，本司不能确保客户收到的货物与商城图片、产地、附件说明完全一致。只能确保为原厂正货！并且保证与当时市场上同样主流新品一致。若本商城没有及时更新，请大家谅解！
                    </p>
                </div>
                <div class="row">
                    <div class="col-md-1 saled-icon"><span class="fa fa-globe"></span></div>
                    <div class="col-md-11 saled-title">全国联保</div>
                </div>
                <div class="row">
                    <p class="col-md-offset-1 col-md-11 saled-content">
                        凭质保证书及学子商城发票，可享受全国联保服务（奢侈品、钟表除外；奢侈品、钟表由学子商城联系保修，享受法定三包售后服务），与您亲临商场选购的商品享受相同的质量保证。学子商城还为您提供具有竞争力的商品价格和运费政策，请您放心购买！
                        <br/>
                        注：因厂家会在没有任何提前通知的情况下更改产品包装、产地或者一些附件，本司不能确保客户收到的货物与商城图片、产地、附件说明完全一致。只能确保为原厂正货！并且保证与当时市场上同样主流新品一致。若本商城没有及时更新，请大家谅解！
                    </p>
                </div>
                <div class="row">
                    <div class="col-md-1 saled-icon"><span class="fa fa-reply"></span></div>
                    <div class="col-md-11 saled-title">无忧退货</div>
                </div>
                <div class="row">
                    <p class="col-md-offset-1 col-md-11 saled-content">
                        客户购买学子商城商品7日内（含7日，自客户收到商品之日起计算），在保证商品完好的前提下，可无理由退货。（部分商品除外，详情请见各商品细则）</p>
                </div>
                <div class="saled-content">
                    <small><b>权利声明：</b><br/>
                        所有商品信息、商品咨询等内容，是学子商城重要的经营资源，未经许可，禁止非法转载使用。<br/>
                        注：本站商品信息均来自于合作方，其真实性、准确性和合法性由信息拥有者（合作方）负责。本站不提供任何保证，并不承担任何法律责任。</small>
                </div>
            </div>
        </div>
    </div>
</div>
<!--页脚开始-->
<div class="clearfix"></div>
<footer class="footer">
    <!-- 品质保障，私人定制等-->
    <div class="text-center rights container">
        <div class="col-md-offset-2 col-md-2">
            <span class="fa fa-thumbs-o-up"></span>
            <p>品质保障</p>
        </div>
        <div class="col-md-2">
            <span class="fa fa-address-card-o"></span>
            <p>私人订制</p>
        </div>
        <div class="col-md-2">
            <span class="fa fa-graduation-cap"></span>
            <p>学生特供</p>
        </div>
        <div class="col-md-2">
            <span class="fa fa-bitcoin"></span>
            <p>专属特权</p>
        </div>
    </div>
    <!--联系我们、下载客户端等-->
    <div class="container beforeBottom">
        <div class="col-md-offset-1 col-md-3">
            <div><img src="../images/index/stumalllogo.png" alt="" class="footLogo"/></div>
            <div><img src="../images/index/footerFont.png" alt=""/></div>
        </div>
        <div class="col-md-4 callus text-center">
            <div class="col-md-4">
                <ul>
                    <li>
                        <a href="#">
                            <p>买家帮助</p>
                        </a>
                    </li>
                    <li><a href="#">新手指南</a></li>
                    <li><a href="#">服务保障</a></li>
                    <li><a href="#">常见问题</a></li>
                </ul>
            </div>
            <div class="col-md-4">
                <ul>
                    <li>
                        <a href="#">
                            <p>商家帮助</p>
                        </a>
                    </li>
                    <li><a href="#">商家入驻</a></li>
                    <li><a href="#">商家后台</a></li>
                </ul>
            </div>
            <div class="col-md-4">
                <ul>
                    <li>
                        <a href="#">
                            <p>关于我们</p>
                        </a>
                    </li>
                    <li><a href="#">关于达内</a></li>
                    <li><a href="#">联系我们</a></li>
                    <li>
                        <span class="fa fa-wechat"></span>
                        <span class="fa fa-weibo"></span>
                    </li>
                </ul>
            </div>
        </div>
        <div class="col-md-4">
            <div class="col-md-5">
                <p>学子商城客户端</p>
                <img src="../images/index/ios.png" class="lf">
                <img src="../images/index/android.png" alt="" class="lf"/>
            </div>
            <div class="col-md-6">
                <img src="../images/index/erweima.png">
            </div>
        </div>
    </div>
    <!-- 页面底部-备案号 #footer -->
    <div class="col-md-12 text-center bottom">
        Copyright © 2018 Tedu.cn All Rights Reserved 京ICP备08000853号-56 <a target="_blank" href="http://www.tedu.cn/">达内时代科技集团有限公司</a>
        版权所有
    </div>
</footer>
<!--页脚结束-->
<!--		<script src="../js/product.js" type="text/javascript" charset="utf-8"></script>-->
<!--		<script src="../js/imgmove.js" type="text/javascript" charset="utf-8"></script>-->
<!--		<script src="../js/jquery-getUrlParam.js"></script>-->
</body>

<script>
    const app = Vue.createApp({
        data() {
            return {
                username: localStorage.getItem("username") !== null ? localStorage.getItem("username") : "去登录",
                isLogin: localStorage.getItem("username") !== null,
                product: {},
                userId: localStorage.getItem("id")
            }
        },
        methods: {
            // 加入购物车
            async addToCart() {
                let response = await request({
                    url: "api/cart/insert",
                    method: "post",
                    data: {
                        productId: this.product.id,
                        num: $("#num").val(),
                        userId: this.userId
                    }
                });
                if (response.code === 20000) {
                    ElementPlus.ElMessage({
                        message: "加入购物车成功",
                        type: "success"
                    });
                } else {
                    ElementPlus.ElMessage({
                        message: response.message,
                        type: "error"
                    });
                }
                // 跳转到购物车页面，等待3秒
                setTimeout(() => {
                    location.href = "cart.html";
                }, 1000);
            },

            // 获取商品信息
            async getProduct() {
                // 获取查询字符串
                let queryString = window.location.search;
                // 使用 URLSearchParams 来解析查询字符串
                let urlParams = new URLSearchParams(queryString);
                // 使用 get 方法来获取特定的参数
                let id = urlParams.get('id');


                // 发送请求
                let response = await request({
                    url: `api/product/${id}`,
                    method: "get",
                });
                if (response.code === 20000) {
                    this.product = response.data;
                    // console.log(this.product);
                    // 构造图片路径，根据原始路径构造/images/portal/11DELLran7000gold/
                    // 5个小图路径，例如：../images/portal/11DELLran7000R1605Ssilvery/1.jpg
                    // 5个大图路径，例如：../images/portal/11DELLran7000R1605Ssilvery/1_big.png
                    let imgPath = `..${this.product.image}`
                    this.product.imgs = [];
                    for (let i = 1; i <= 5; i++) {
                        this.product.imgs.push({
                            small: `${imgPath}${i}.jpg`,
                            big: `${imgPath}${i}_big.png`
                        });
                    }
                    await this.updateProductStats()
                } else {
                    ElementPlus.ElMessage({
                        message: response.message,
                        type: "error"
                    });
                }
            },
            async updateProductStats(){
                let res = await request({url:`/product/stats/${this.product.id}`,method:"put"});
            },
            async addToFavorites(){
                let res = await request({
                    url:`/api/favorite/add/${this.product.id}`,
                    method:'post'
                })
                this.getProduct()
            },
            async removeFromFavorites(){
                let res = await request({
                    url:`/api/favorite/cancel/${this.product.id}`,
                    method:'delete'
                })
                this.getProduct()
            }
        },
        mounted() {
             this.getProduct();

        },
    })
    app.mount('#app')
</script>

</html>